package kg.aibek.projecteuler.p51;

import java.util.ArrayList;
import java.util.List;

public class Problem61 {
	public void solve() {
		List<Integer> triangles = new ArrayList<Integer>();
		List<Integer> squares = new ArrayList<Integer>();
		List<Integer> pentagonals = new ArrayList<Integer>();
		List<Integer> hexagonals = new ArrayList<Integer>();
		List<Integer> heptagonals = new ArrayList<Integer>();
		List<Integer> octagonals = new ArrayList<Integer>();

		int n = 0;
		int i = 0;
		while (n < 10000) {
			n = i * (i + 1) / 2;
			if (n >= 1000) {
				triangles.add(n);
			}
			i++;
		}
		i = 0;
		n = 0;
		while (n < 10000) {
			n = i * i;
			if (n >= 1000) {
				squares.add(n);
			}
			i++;
		}
		i = 0;
		n = 0;
		while (n < 10000) {
			n = i * (3 * i - 1) / 2;
			if (n >= 1000) {
				pentagonals.add(n);
			}
			i++;
		}
		i = 0;
		n = 0;
		while (n < 10000) {
			n = i * (2 * i - 1);
			if (n >= 1000) {
				hexagonals.add(n);
			}
			i++;
		}
		i = 0;
		n = 0;
		while (n < 10000) {
			n = i * (5 * i - 3) / 2;
			if (n >= 1000) {
				heptagonals.add(n);
			}
			i++;
		}
		i = 0;
		n = 0;
		while (n < 10000) {
			n = i * (3 * i - 2);
			if (n >= 1000) {
				octagonals.add(n);
			}
			i++;
		}

		List<List<Integer>> ll = new ArrayList<List<Integer>>();
		ll.add(triangles);
		ll.add(squares);
		ll.add(pentagonals);
		ll.add(hexagonals);
		ll.add(heptagonals);
		ll.add(octagonals);

		for (int i1 = 0; i1 < 6; i1++) {
			List<Integer> list1 = ll.get(i1);
			for (Integer ii1 : list1) {
				String str11 = (ii1 + "").substring(0, 2);
				String str12 = (ii1 + "").substring(2);
				for (int i2 = 0; i2 < 6; i2++) {
					if (i1 == i2)
						continue;

					List<Integer> list2 = ll.get(i2);
					for (Integer ii2 : list2) {
						String str21 = (ii2 + "").substring(0, 2);
						String str22 = (ii2 + "").substring(2);

						if (!str12.equals(str21))
							continue;

						for (int i3 = 0; i3 < 6; i3++) {
							if (i1 == i3 || i2 == i3)
								continue;
							List<Integer> list3 = ll.get(i3);
							for (Integer ii3 : list3) {
								String str31 = (ii3 + "").substring(0, 2);
								String str32 = (ii3 + "").substring(2);

								if (!str22.equals(str31))
									continue;

								for (int i4 = 0; i4 < 6; i4++) {
									if (i1 == i4 || i2 == i4 || i3 == i4)
										continue;
									List<Integer> list4 = ll.get(i4);
									for (Integer ii4 : list4) {
										String str41 = (ii4 + "").substring(0,
												2);
										String str42 = (ii4 + "").substring(2);

										if (!str32.equals(str41))
											continue;

										for (int i5 = 0; i5 < 6; i5++) {
											if (i1 == i5 || i2 == i5
													|| i3 == i5 || i4 == i5)
												continue;
											List<Integer> list5 = ll.get(i5);
											for (Integer ii5 : list5) {
												String str51 = (ii5 + "")
														.substring(0, 2);
												String str52 = (ii5 + "")
														.substring(2);

												if (!str42.equals(str51))
													continue;

												for (int i6 = 0; i6 < 6; i6++) {
													if (i1 == i6 || i2 == i6
															|| i3 == i6
															|| i4 == i6
															|| i5 == i6)
														continue;

													List<Integer> list6 = ll
															.get(i6);
													for (Integer ii6 : list6) {
														String str61 = (ii6 + "")
																.substring(0, 2);
														String str62 = (ii6 + "")
																.substring(2);

														if (str52.equals(str61)
																&& str62.equals(str11)) {
															System.out
																	.println(str11
																			+ str12
																			+ " "
																			+ str21
																			+ str22
																			+ " "
																			+ str31
																			+ str32
																			+ " "
																			+ str41
																			+ str42
																			+ " "
																			+ str51
																			+ str52
																			+ " "
																			+ str61
																			+ str62);
														}

													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}

		System.out.println("El finito");
	}

	public static void main(String[] args) {
		// Problem61 p = new Problem61();
		// p.solve();

		int[] a = { 1281, 8128, 2882, 8256, 5625, 2512 };
		int sum = 0;
		for (int i : a) {
			sum += i;
		}
		System.out.println(sum);
	}
}
